package com.machine.action.order;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.machine.bean.OrderForm;
import com.machine.bean.PriceOrder;
import com.machine.service.order.OrderServer;
import com.opensymphony.xwork2.ActionSupport;

@Component("addOrderAction")
@Scope(value = "prototype")
public class AddOrderAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private OrderServer orderServer;
	private OrderForm orderForm;
	private PriceOrder priceOrder;
	
	

	public PriceOrder getPriceOrder() {
		return priceOrder;
	}

	public void setPriceOrder(PriceOrder priceOrder) {
		this.priceOrder = priceOrder;
	}

	public OrderForm getOrderForm() {
		return orderForm;
	}

	public void setOrderForm(OrderForm orderForm) {
		this.orderForm = orderForm;
	}

	public OrderServer getOrderServer() {
		return orderServer;
	}

	@Resource
	public void setOrderServer(OrderServer orderServer) {
		this.orderServer = orderServer;
	}

	@Override
	public String execute() throws Exception {
		
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		String mydate = f.format(date);
		orderForm.setOuttime(mydate);
		orderForm.setAllprice(orderForm.getUnitprice() * orderForm.getAmount());
		orderServer.addOrder(orderForm);

		return super.execute();
	}

}
